<%-- 
    Document   : hotItemScanner
    Created on : Apr 5, 2013, 1:35:01 PM
    Author     : asikprad
--%>

<%@tag description="put the tag description here" pageEncoding="windows-1252"%>
<%@ attribute name="xmlContentId" required="true"
              description="Id for the xml content to scan for hot items."%>

<%@ attribute name="branchId" required="true"
              description="Id for the current branch."%>

<script language="Javascript" type="text/javascript">
    var HotItem = function(ditaContainer, branchId) {
        this.ditaContainer = ditaContainer;
        this.branchId = branchId;
        this.currentPointer = 0;
        this.permanentPreview = "";
        this.originalPreview = "";

    };
    HotItem.prototype.getDitaContainerValue = function() {
        return $("textarea[id='" + this.ditaContainer + "']").val();
    };
    HotItem.prototype.getHeatedMap = function() {
        return this.heatedMap;
    };

    HotItem.prototype.addCheckbox = function(item) {
        var container = $('#hot-terms');
        var html = '<input type="checkbox" disabled="disabled" id="' + item.term + '" value="'
                + item.term + '"checked /> <label for="' + item.term + '">'
                + item.term + '</label><br/>';

        container.append($(html));
    };
    HotItem.prototype.addMessage = function(message) {
        $('#hot-terms-message').empty().append(message);
    };
    HotItem.prototype.alertMessage = function(message) {
        alert(message);
    };
    HotItem.prototype.error = function() {
        alert("error");
    };
    HotItem.prototype.setHeatedMap = function(heatedMap) {
        this.heatedMap = heatedMap;
    };

    HotItem.prototype.currentPreview = function() {
        return $('#hotItem-preview').html();
    };
    HotItem.prototype.updatePreview = function(body) {
        $('#hotItem-preview').empty().append(body);
    };
    HotItem.prototype.heat = function() {
        this.permanentPreview = this.currentPreview();
        this.currentPointer--;
    };

    HotItem.prototype.findPrev = function() {
        var str = this.permanentPreview;
        var replaceStr = this.replaceIndex(str, this.currentPointer - 1);
        if (str === replaceStr) {
            this.addMessage("beginning of search");
        } else {
            this.updatePreview(replaceStr);
        }
    };
    HotItem.prototype.findNext = function() {
        var str = this.permanentPreview;
        var replaceStr = this.replaceIndex(str, this.currentM + 1);
        if (str === replaceStr) {
            this.addMessage("end of search");
        } else {
            this.updatePreview(replaceStr);
        }
    };
    HotItem.prototype.replaceIndex = function(body, n) {
        m = 0;
        return body.replace(new RegExp('(guest' + '(?!<\/b>))|(CAS' + '(?!<\/b>))', "ig"), function(x) {
            m++;
            if (n === m) {
                this.currentPointer = m;
                return "<b>" + x + "</b>";
            } else {
                return x;
            }
        });
    };

    HotItem.prototype.startOver = function() {
        this.permanentPreview = this.originalPreview;
        this.currentPointer = 0;
        this.updatePreview(this.originalPreview);
    };
    var hotItemScanner = new Object();
    hotItemScanner.startScan = function() {
        var kmsHotItem = new HotItem('${xmlContentId}', '${branchId}');
        hotItemScanner.kmsHotItem=kmsHotItem;
        kmsHotItem.permanentPreview = kmsHotItem.currentPreview();
        kmsHotItem.originalPreview = kmsHotItem.currentPreview();
        $.ajax({
            url: "scan",
            type: "GET",
            dataType: 'json',
            success: function(data) {
                kmsHotItem.setHeatedMap(data);
                $.map(data, function(value) {
                    kmsHotItem.addMessage("");
                    kmsHotItem.addCheckbox(value);
                });
            }});
        kmsHotItem.heat();

    };
    hotItemScanner.findNext = function () {
        
    };
    

</script>
<table>
    <tr>
        <td class="tab-subhead">Hot Terms</td>
        <td class="tab-subhead">Preview</td>
    </tr>
    <tr>
        <td valign="top">
            <div id="hot-terms-message"></div>
            <div id="hot-terms"></div>
        </td>
        <td valign="top">

            <div id="hotItem-preview">
                <p>This should point to deny.dita: <kba keyref="bogus"/></p>
                <p>First, try <xref href="http://google.com" scope="external">Google</xref>.</p>
                <p>   If you use a guest account to log
                    into IU services (e.g., parents who use OneStart to pay bursar bills, non-IU students
                    CAS Oncourse CL sites for audited classes), you may CAS a message requesting that
                    you reset your Guest password. This is a legitimate request from UITS; it is not a phishing
                    attempt. This step is necessary because of improvements made to the internal management
                    of Guest accounts.</p>
                <p>You will need to reset your password before you can authenticate to <term keyref="abcd.xhtml">CAS</term>. If
                you know your old Guest password, you can reset your password at:
                <lines>
                    <xref conref="l-guestpasswordchangeform.dita#kbdoc/link"/>
                </lines>
                </p>
                <p><note audience="sc">SC can look up Guest information in AMS Admin. From there, you will be
                    able to send or resend the Guest activation PIN.</note></p>
                <fig conref="i-kblogo.dita#kbdoc/image"/>
                <section conref="b-scbreak.dita#kbdoc/content"/>
                <section conref="b-ims-guest-initial-directions.dita#kbdoc/content"/>
            </div>
        </td>
    </tr>

</table>
<div class="buttons">
    <input type="submit" onclick="hotItem.findPrev();
        return false;" name="prev" value="prev"/>
    <input type="submit" onclick="hotItem.heat();
        return false;" name="heat" value="heat"/>
    <input type="submit" onclick="hotItem.findNext();
        return false;" name="next" value="next"/>

    <input type="submit" onclick="hotItem.startOver();
        return false;" name="startOver" value="start over?"/>
</div>